#include "Frm05.h"

Frm05::Frm05(HmiApp* app, STTWidget *par, const string& id, const string& desc) : STTPage(app->getRuntime(), par, id, desc) {
	hmiApp = app;
}

Frm05::~Frm05() {
}

void Frm05::onInit() {

}

void Frm05::createParts() {
	setMainArg(0, 0, 1024, 600);
	setMainStyle(0, 0xffffff, 0xffffff, 0, 255, 0, 0xc0c0c0);

	/*----------------------------- Panel : wMPanel1                     -----------------------------*/
	wMPanel1 = new STTPanel(p_rt, this, "wMPanel1");
	wMPanel1->setMainArg(283, 275, 457, 295, 0);
	wMPanel1->setMainStyle(0, 0xffffff, 0xffffff, GradDir::NONE, 255, 10, 0xff80c0);

	/*----------------------------- Label : wMLabel1                     -----------------------------*/
	wMLabel1 = new STTLabel(p_rt, wMPanel1, "wMLabel1");
	wMLabel1->setMainArg(60, 45, 159, 60, "标签", TextAlign::LEFT, LabelLongMode::CLIP, 30);
	wMLabel1->setFonts(0xffff, 16, "文泉驿微米黑", 0);
	wMLabel1->setMainStyle(0, 0xff, 0xffffff, GradDir::NONE, 2, 0x0, 140);
	wMLabel1->setFormatText(TextAlign::LEFT, LabelLongMode::CLIP, 30);

	/*----------------------------- Text : wMText1                       -----------------------------*/
	wMText1 = new STTTextArea(p_rt, wMPanel1, "wMText1");
	wMText1->setMainArg(64, 130, 329, 35, false, true, TextAlign::CENTER, -1, -1, -99999999, 99999999, false);
	wMText1->setMainStyle(7, 0xffffff, 0xffffff, 0, 2, 0xc0c0c0, 4, 4, 4, 4, 255);
	wMText1->setPlaceholderText("")->setMaxLength(0)->setAcceptedChars("")->setImeMode(IME::UC);
	wMText1->setFont(0x0, 16, "文泉驿微米黑", 0);

	/*----------------------------- Button : wMButton21                  -----------------------------*/
	wMButton21 = new STTButton(p_rt, wMPanel1, "wMButton21", 0);
	wMButton21->setMainArg(376, 51, 98, 48, false);
	wMButton21->setPressedArg("click me!", 0x0, "文泉驿微米黑", 16, 0);
	wMButton21->setPressedStyle(8, 255, 0xebebeb, 0x999999, 1, 1, 0x999999, 1, 0xebebeb);
	wMButton21->setReleasedArg("click me!", 0x0, "文泉驿微米黑", 16, 0);
	wMButton21->setReleasedStyle(5, 255, 0xebebeb, 0x999999, 1, 1, 0x999999, 1, 0xebebeb);
	wMButton21->onEventHandler(Event::CLICKED, this, (EHandler) &Frm05::wMButton21_clk_cb);

	/*----------------------------- Slider : wMSlider5                   -----------------------------*/
	wMSlider5 = new STTSlider(p_rt, wMPanel1, "wMSlider5");
	wMSlider5->setMainArg(92, 206, 273, 42, 50, 0, 100, false);
	wMSlider5->setMainStyle(9999, 0xa0a0a0, 0xffffff, 0, 0, 0xa0a0a0, 0, 0x0, NULL);
	wMSlider5->setIndicStyle(9999, 0x1a2b1, 0xffffff, 0, 0, 0x1a2b1, 0, 0xffffff, NULL);
	wMSlider5->setKnobStyle(7, 0x1a2b1, 0xffffff, 0, 0, 0x1a2b1, 0, 0x0, NULL, 7);

	/*----------------------------- MButton : wMMButton1                 -----------------------------*/
	wMMButton1 = new STTButton(p_rt, this, "wMMButton1", 1);
	wMMButton1->setMainArg(0, 0, 100, 50, false);
	wMMButton1->setImg("1", "./images/arrow_34_100X50.gray.svg", "");
	wMMButton1->setImg("0", "./images/arrow_34_100X50.svg", "");
	wMMButton1->bindOpenFormHandler(Event::CLICKED, "Frm01", PageMode::NEWWIN, NULL);

	/*----------------------------- Panel : wMPanel2                     -----------------------------*/
	wMPanel2 = new STTPanel(p_rt, this, "wMPanel2");
	wMPanel2->setMainArg(297, 0, 121, 201, 0);
	wMPanel2->setMainStyle(0, 0xffffff, 0xffffff, GradDir::NONE, 255, 1, 0xc0c0c0);

	/*----------------------------- Slider : wMSlider2                   -----------------------------*/
	wMSlider2 = new STTSlider(p_rt, wMPanel2, "wMSlider2");
	wMSlider2->setMainArg(21, 13, 9, 167, 50, 0, 255, false);
	wMSlider2->setMainStyle(9999, 0xa0a0a0, 0xffffff, 0, 0, 0xa0a0a0, 0, 0x0, NULL);
	wMSlider2->setIndicStyle(9999, 0xff0000, 0xffffff, 0, 0, 0x1a2b1, 0, 0xffffff, NULL);
	wMSlider2->setKnobStyle(7, 0xff0000, 0xffffff, 0, 0, 0x1a2b1, 0, 0x0, NULL, 7);
	wMSlider2->onEventHandler(Event::VALUE_CHANGED, this, (EHandler) &Frm05::wMSlider2_vch_cb);

	/*----------------------------- Slider : wMSlider3                   -----------------------------*/
	wMSlider3 = new STTSlider(p_rt, wMPanel2, "wMSlider3");
	wMSlider3->setMainArg(55, 13, 9, 167, 50, 0, 255, false);
	wMSlider3->setMainStyle(9999, 0xa0a0a0, 0xffffff, 0, 0, 0xa0a0a0, 0, 0x0, NULL);
	wMSlider3->setIndicStyle(9999, 0xff00, 0xffffff, 0, 0, 0x1a2b1, 0, 0xffffff, NULL);
	wMSlider3->setKnobStyle(7, 0xff00, 0xffffff, 0, 0, 0x1a2b1, 0, 0x0, NULL, 7);
	wMSlider3->onEventHandler(Event::VALUE_CHANGED, this, (EHandler) &Frm05::wMSlider3_vch_cb);

	/*----------------------------- Slider : wMSlider4                   -----------------------------*/
	wMSlider4 = new STTSlider(p_rt, wMPanel2, "wMSlider4");
	wMSlider4->setMainArg(89, 13, 9, 167, 50, 0, 255, false);
	wMSlider4->setMainStyle(9999, 0xa0a0a0, 0xffffff, 0, 0, 0xa0a0a0, 0, 0x0, NULL);
	wMSlider4->setIndicStyle(9999, 0xff, 0xffffff, 0, 0, 0x1a2b1, 0, 0xffffff, NULL);
	wMSlider4->setKnobStyle(7, 0xff, 0xffffff, 0, 0, 0x1a2b1, 0, 0x0, NULL, 7);
	wMSlider4->onEventHandler(Event::VALUE_CHANGED, this, (EHandler) &Frm05::wMSlider4_vch_cb);

	/*----------------------------- Slider : wMSlider9                   -----------------------------*/
	wMSlider9 = new STTSlider(p_rt, this, "wMSlider9");
	wMSlider9->setMainArg(264, 17, 9, 167, 50, 0, 255, false);
	wMSlider9->setMainStyle(9999, 0xa0a0a0, 0xffffff, 0, 0, 0xa0a0a0, 0, 0x0, NULL);
	wMSlider9->setIndicStyle(9999, 0x0, 0xffffff, 0, 0, 0x1a2b1, 0, 0xffffff, NULL);
	wMSlider9->setKnobStyle(7, 0x0, 0xffffff, 0, 0, 0x1a2b1, 0, 0x0, NULL, 7);
	wMSlider9->onEventHandler(Event::VALUE_CHANGED, this, (EHandler) &Frm05::wMSlider9_vch_cb);

	/*----------------------------- Label : wMLabel3                     -----------------------------*/
	wMLabel3 = new STTLabel(p_rt, this, "wMLabel3");
	wMLabel3->setMainArg(232, 220, 74, 32, "不透明度(0-255)", TextAlign::CENTER, LabelLongMode::WRAP, 30);
	wMLabel3->setFonts(0x0, 12, "文泉驿微米黑", 0);
	wMLabel3->setMainStyle(0, 0xffffff, 0xffffff, GradDir::NONE, 0, 0x0, 0);
	wMLabel3->setFormatText(TextAlign::CENTER, LabelLongMode::WRAP, 30);

	/*----------------------------- Label : wMLabel4                     -----------------------------*/
	wMLabel4 = new STTLabel(p_rt, this, "wMLabel4");
	wMLabel4->setMainArg(321, 220, 74, 16, "主色", TextAlign::CENTER, LabelLongMode::WRAP, 30);
	wMLabel4->setFonts(0x0, 12, "文泉驿微米黑", 0);
	wMLabel4->setMainStyle(0, 0xffffff, 0xffffff, GradDir::NONE, 0, 0x0, 0);
	wMLabel4->setFormatText(TextAlign::CENTER, LabelLongMode::WRAP, 30);

	/*----------------------------- Slider : wMSlider10                  -----------------------------*/
	wMSlider10 = new STTSlider(p_rt, this, "wMSlider10");
	wMSlider10->setMainArg(435, 17, 9, 167, 0, 0, 20, false);
	wMSlider10->setMainStyle(9999, 0xa0a0a0, 0xffffff, 0, 0, 0xa0a0a0, 0, 0x0, NULL);
	wMSlider10->setIndicStyle(9999, 0x0, 0xffffff, 0, 0, 0x1a2b1, 0, 0xffffff, NULL);
	wMSlider10->setKnobStyle(7, 0x0, 0xffffff, 0, 0, 0x1a2b1, 0, 0x0, NULL, 7);
	wMSlider10->onEventHandler(Event::VALUE_CHANGED, this, (EHandler) &Frm05::wMSlider10_vch_cb);

	/*----------------------------- Label : wMLabel6                     -----------------------------*/
	wMLabel6 = new STTLabel(p_rt, this, "wMLabel6");
	wMLabel6->setMainArg(403, 220, 74, 32, "宽度", TextAlign::CENTER, LabelLongMode::WRAP, 30);
	wMLabel6->setFonts(0x0, 12, "文泉驿微米黑", 0);
	wMLabel6->setMainStyle(0, 0xffffff, 0xffffff, GradDir::NONE, 0, 0x0, 0);
	wMLabel6->setFormatText(TextAlign::CENTER, LabelLongMode::WRAP, 30);

	/*----------------------------- Slider : wMSlider11                  -----------------------------*/
	wMSlider11 = new STTSlider(p_rt, this, "wMSlider11");
	wMSlider11->setMainArg(635, 17, 9, 167, 0, 0, 20, false);
	wMSlider11->setMainStyle(9999, 0xa0a0a0, 0xffffff, 0, 0, 0xa0a0a0, 0, 0x0, NULL);
	wMSlider11->setIndicStyle(9999, 0x0, 0xffffff, 0, 0, 0x1a2b1, 0, 0xffffff, NULL);
	wMSlider11->setKnobStyle(7, 0x0, 0xffffff, 0, 0, 0x1a2b1, 0, 0x0, NULL, 7);
	wMSlider11->onEventHandler(Event::VALUE_CHANGED, this, (EHandler) &Frm05::wMSlider11_vch_cb);

	/*----------------------------- Label : wMLabel7                     -----------------------------*/
	wMLabel7 = new STTLabel(p_rt, this, "wMLabel7");
	wMLabel7->setMainArg(603, 220, 74, 32, "间距", TextAlign::CENTER, LabelLongMode::WRAP, 30);
	wMLabel7->setFonts(0x0, 12, "文泉驿微米黑", 0);
	wMLabel7->setMainStyle(0, 0xffffff, 0xffffff, GradDir::NONE, 0, 0x0, 0);
	wMLabel7->setFormatText(TextAlign::CENTER, LabelLongMode::WRAP, 30);

	/*----------------------------- Label : wMLabel10                    -----------------------------*/
	wMLabel10 = new STTLabel(p_rt, this, "wMLabel10");
	wMLabel10->setMainArg(0, 49, 227, 508, "轮廓演示", TextAlign::CENTER, LabelLongMode::CLIP, 30);
	wMLabel10->setFonts(0xff0000, 28, "文泉驿微米黑", 0);
	wMLabel10->setMainStyle(0, 0x80ffff, 0xffffff, GradDir::NONE, 0, 0x0, 140);
	wMLabel10->setFormatText(TextAlign::CENTER, LabelLongMode::CLIP, 30);

	/*called after widget created.*/

	return; //createParts END
}

static STTWidget* pp = NULL;

void loadbg(Frm05* frm) {
	pp = frm->wMPanel1;
	STTStyleOutline *p = pp->getStyle()->p_outline;
	int opa = p->getOpa();
	int clr1 = p->getColor();
	int width = p->getWidth();
	int pad = p->getPad();

	frm->wMSlider9->setValue(opa, true);

	frm->wMSlider2->setValue((clr1>>16)&0xff, true);
	frm->wMSlider3->setValue((clr1>>8)&0xff, true);
	frm->wMSlider4->setValue((clr1>>0)&0xff, true);

	frm->wMSlider10->setValue(width, true);

	frm->wMSlider11->setValue(pad, true);

}

void Frm05::onLoad() {
	wMPanel1->getStyle()->p_outline->setWidth(10);
	AsynWorker *worker = new AsynWorker(getRuntime()->getAppInstance(this_thread::get_id()));
	//如需传入局部变量，可在网上搜索lambda表达式的用法
	worker->invoke([this]() {
		std::this_thread::sleep_for(std::chrono::milliseconds(200));//延时200ms
	})->onFinished([this]() {
		loadbg(this);//加载完成时，为确保控件属性已刷新，延时读取控件属性
	})->start();

}

bool Frm05::onClosing() {
	return true;
}

void Frm05::onDispose() {

}

void Frm05::onMyEvent(uint16_t code, LvEvent e) {
	cout<<"onMyEvent"<<endl;
}

static int itmp = 0;

void Frm05::wMButton21_clk_cb(uint16_t code, LvEvent e) {
	/*wMButton21（click me!）的点击事件*/
	cout << "click me!" << endl;
}

void updatebg(Frm05* frm) {
	pp = frm->wMPanel1;
	STTStyleOutline *p = pp->getStyle()->p_outline;

	int opa = frm->wMSlider9->getValue();
	p->setOpa(opa);
	{
		int r1 = frm->wMSlider2->getValue();
		int g1 = frm->wMSlider3->getValue();
		int b1 = frm->wMSlider4->getValue();
		int rgb1 = (r1<<16)+(g1<<8)+b1;
		p->setColor(rgb1);
	}
	int width = frm->wMSlider10->getValue();
	p->setWidth(width);

	int pad = frm->wMSlider11->getValue();
	p->setPad(pad);

}

void Frm05::wMSlider2_vch_cb(uint16_t code, LvEvent e) {
	updatebg(this);
}

void Frm05::wMSlider3_vch_cb(uint16_t code, LvEvent e) {
	updatebg(this);
}

void Frm05::wMSlider4_vch_cb(uint16_t code, LvEvent e) {
	updatebg(this);
}

void Frm05::wMSlider9_vch_cb(uint16_t code, LvEvent e) {
	updatebg(this);
}

void Frm05::wMSlider10_vch_cb(uint16_t code, LvEvent e) {
	updatebg(this);
}

void Frm05::wMSlider11_vch_cb(uint16_t code, LvEvent e) {
	updatebg(this);
}
